
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = Utils
 * DateTime = Sat Feb 05 2022 15:06:54 GMT+0800 (China Standard Time)
 * Author = vvc_zeng
 * FileBasename = Utils.ts
 * FileBasenameNoExtension = Utils
 * URL = db://assets/script/utils/Utils.ts
 * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
 *
 */
 
@ccclass('Utils')
export class Utils extends Component {
    static getRandomRange(x, y, num?) {
        if (num > 1) {
            let res = [];
            for (let i = x; i <= y; i++) {
                res.push(i);
            }
            let final = [];
            for (let j = 0; j < num; j++) {
                final.push(...(res.splice(<number>this.getRandomRange(0, res.length - 1), 1)))
            }
            return final;
        } else {
            return Number(Math.round(Math.random() * (y - x)) + x);
        }
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
 */
